package org.example.what_mall.vo;

import lombok.Data;
import org.example.what_mall.entity.Order;
import org.example.what_mall.entity.User;
import org.example.what_mall.enums.OrderState;

import java.time.LocalDateTime;

@Data
public class OrderInfoVO {
    private Integer id;
    private User user;
    private String goods;
    private String spec;
    private Integer num;
    private Integer amount;
    private String state;
    private LocalDateTime time;

    public static OrderInfoVO of(Order order, User user, String goods, String spec) {
        OrderInfoVO vo = new OrderInfoVO();

        vo.setId(order.getId());
        vo.setUser(user);
        vo.setGoods(goods);
        vo.setSpec(spec);
        vo.setNum(order.getNum());
        vo.setAmount(order.getAmount());

        Integer state = order.getState();
        if(state == -1) vo.setState(OrderState.ALL.getDescription());
        else if (state == 0) vo.setState(OrderState.CART.getDescription());
        else if (state == 1) vo.setState(OrderState.UNPAID.getDescription());
        else if (state == 2) vo.setState(OrderState.UNSHIPPED.getDescription());
        else if (state == 3) vo.setState(OrderState.SHIPPED.getDescription());

        vo.setTime(order.getCreatetime());

        return vo;
    }
}
